package com.example.hello1;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity2 extends AppCompatActivity {
    int score1;
    int score2;
  private static final String TAG="BALLACTIVITY";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
        setContentView(R.layout.activity_main3);

    }

    public void click(View btn) {

        Log.i(TAG, "click");
        if (btn.getId() == R.id.button3) {
            score1 = score1 + 3;
            System.out.println("why");
        } else if (btn.getId() == R.id.button2) {

            score1 = score1+ 2;
            System.out.println("any");
        } else if (btn.getId() == R.id.button1) {
            score1 = score1 + 1;
        } else if (btn.getId() == R.id.button7){
            score1 = 0;
        }
        Log.i(TAG, "click: kkkkkk");
        TextView out= findViewById(R.id.textView2);
        out.setText("" + score1);
    }
    public void click2(View btn) {
        int score=0;
        Log.i(TAG, "click");
        if (btn.getId() == R.id.button6) {
            score2 = score2 + 3;
        } else if (btn.getId() == R.id.button5) {

            score2 = score2 + 2;
        } else if (btn.getId() == R.id.button4) {
            score2 = score2 + 1;
        } else if (btn.getId() == R.id.button7){
            score = 0;
        }
        Log.i(TAG, "click: kkkkkk");
        TextView out= findViewById(R.id.textView4);
        out.setText("" + score2);
    }

    @Override
    protected void onSaveInstanceState(@NonNull Bundle outState) {
        super.onSaveInstanceState(outState);
       outState.putInt("scorea",score1);
       outState.putInt("scoreb",score2);
       Log.i(TAG,"保存数据a："+score1);
       Log.i(TAG,"保存数据b："+score2);

    }

    @Override
    protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        score1=savedInstanceState.getInt("scorea",score1);
        score2=savedInstanceState.getInt("scoreb",score2);
        Log.i(TAG,"恢复数据a："+score1);
        Log.i(TAG,"恢复数据b："+score2);
        TextView out= findViewById(R.id.textView2);
        out.setText("" + score1);
        Log.i(TAG, "click: kkkkkk");
        TextView out2= findViewById(R.id.textView4);
        out2.setText("" + score2);


    }
}